package com.yxuan.springboot.service.impl;

import com.yxuan.springboot.mapper.TestRecordsMapper;
import com.yxuan.springboot.mapper.TestReleaseMapper;
import com.yxuan.springboot.model.TestRecords;
import com.yxuan.springboot.service.TestRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;

/**
 * 
 * @author zchao
 *    TestRecords业务层实现类
 * @date 2023-05-16 14:22:56
 */
@Service
@Transactional
public class TestRecordsServiceImpl extends BaseServiceImpl<TestRecords> implements TestRecordsService {


    @Autowired
    private TestRecordsMapper testRecordsMapper;
//    创建测试记录
    @Override
    public HashMap<String, Object> createRecords(TestRecords entity) throws Exception {
        HashMap<String, Object> result = new HashMap<>();
        Date date = new Date();
        Timestamp timestamp = new Timestamp(date.getTime());
        entity.setSubmitTime(timestamp);
        testRecordsMapper.insert(entity);
//        计算成绩
//        未完成但保存
        if (entity.getStatus().equals("0")){
            entity.setGrade(0);
            testRecordsMapper.update(entity);
            result.put("result","success");
            TestRecords testRecords = testRecordsMapper.queryObjectByPramas(entity);
            result.put("recordid",testRecords.getId());
            return result;
        }
//        已完成


        return null;
    }
}
